<template>
  <div class="user-manage innerPageTable-out-flex">
    <search-form
      @search="searchHandle"
      @reset="resetHandle"
      :label-width="170"
      :form-data="formData"
    ></search-form>

    <InnerPageTable ref="listTable" :config="pageTableConfig">
      <div slot="table-bar">
<!--        <Button @click.native="exportHandle()">导出</Button>-->
        <Button @click.native="addHandle">新建</Button>
      </div>
    </InnerPageTable>
  </div>
</template>

<script>
import SearchForm from "@/components/common/SearchForm";
import { mixin } from "@/views/superviseInfo/mix/mixin";
import { configForm, generateColumns } from './constant'
import { superviseInfoAPI } from "@api/superviseInfo";
import userEditor from "@/views/user-manage/userEditor";

export default {
  name: "index",
  mixins: [mixin],
  components: {
    SearchForm,
    userEditor
  },
  computed: {
    searchData() {
      return configForm.bind(this)()
    }
  },
  data() {
    return {
      pageTableConfig: {
        loadDataFn: this.getTableList,
        columns: generateColumns.bind(this)(),
        initParam: {
          crsrmReporterName: '',
          crsrmReporterLdap: '',
          userType: '',
          crsrmPurchaserSbu: ''
        },
        autoFirst: true,
        selectionAreaItem: { key: "id", title: "id" },
        allSelection: [],
        onSelectionChange: this.selectHandle
      },
      selectData: []
    }
  },
  methods: {
    getTableList(tableObj) {
      let { responseProcess, param, initParam } = tableObj;
      const params = {
        ...initParam,
        ...param
      }
      superviseInfoAPI.getUseList(params).then(res => {
        responseProcess(res.data);
      })
    },
    selectHandle(data) {
      this.selectData = data.map(item => item.id)
      console.log(this.selectData, 'selectData');
    },
    exportHandle() {

    },
    detailMethod(row) {
      new this.$pageModal(
        userEditor,
        {
          props: {
            handleType: 'detail',
            id: row.id
          }
        }
      );
    },
    editHandle(row) {
      new this.$pageModal(
        userEditor,
        {
          props: {
            handleType: 'edit',
            id: row.id
          }
        },
        () => {
          this.searchHandle();
        }
      );
    },
    addHandle() {
      new this.$pageModal(
        userEditor,
        {
          props: {
            handleType: 'add'
          }
        },
        () => {
          this.searchHandle();
        }
      );
    },
    deleteHandle(row) {
      this.$confirm
        .warning('确定删除此条权限，删除后不可恢复，是否继续？')
        .then(() => {
          superviseInfoAPI.deletePurview(row).then(res => {
            this.$message.success('操作成功')
            this.searchHandle()
          })
        })
        .catch(() => {
        });
    },
  }
};
</script>

<style scoped>

</style>
